﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AdminSendMessage_AdminViewMess : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (DongDong.Common.Misc.GetQueryString("Check") == "true")
            {
                int ValueID = DongDong.Common.Misc.GetQueryStringAsInt("MessID");
                ZNXX objZNXX = ZNXX.GetByID(ValueID);
                if (objZNXX.Status != (int)ZNXX.statusXX.已读)
                {
                    objZNXX.Status = (int)ZNXX.statusXX.已读;
                    objZNXX.Update();

                }
                Response.Clear();
                Response.Write("Success");
                Response.End();
            }
            else
            {
                PopulateDrp();
                string IsRead = DongDong.Common.Misc.GetQueryString("IsRead");
                if (IsRead == "false")
                    drpSFRead.SelectedValue = ((int)ZNXX.statusXX.未读).ToString();
            }
        }
    }

    public void PopulateDrp()
    {
        drpSFRead.PopulateFromEnum<ZNXX.statusXX>();
        drpSFRead.Items.Insert(0, new ListItem("请选择", "0"));
    }
    public void PopulateMessage()
    {
        AdminUser objAdminUser = AdminUser.GetCurrent();
        if (objAdminUser != null)
        {
            lvSendMessage.DataSource = ZNXX.GetAllByConditon(0, objAdminUser.ID, txtTimeFrom.Text, txtTimeTo.Text, DongDong.Common.Misc.ConvertToInt(drpSFRead.SelectedValue), txtKey.Text, (int)ZNXX.ZXXXType.后台);
            lvSendMessage.DataBind();
        }
    }
    public string ReturnZUserName(object UserID)
    {
        string UserName = "暂无信息";
        AdminUser objUserInfo = AdminUser.Get(DongDong.Common.Misc.ConvertToInt(UserID));
        if (objUserInfo != null)
        {
            UserName = objUserInfo.UserName;
        }
        return UserName;
    }

    public string ReturnZT(object ZT)
    {
        string ZhuangTai = "";
        if ((int)ZT == (int)ZNXX.statusXX.未读)
        {
            ZhuangTai = "<span style='color:red'>" + "未读" + "</span>";
        }
        else
        {
            ZhuangTai = "已读";
        }
        return ZhuangTai;
    }

    protected void lvSendMessage_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateMessage();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvSendMessage.Items.Count == 0)
            PopulateMessage();
    }
    protected void btn_search_Click_Click(object sender, EventArgs e)
    {
        PopulateMessage();
    }
}